import CartList from '@/views/cartList/index.vue'
import Category from '@/views/category/index.vue'
import CheckOut from '@/views/checkout/index.vue'
import Detail from '@/views/detail/index.vue'
import Home from '@/views/home/index.vue'
import Layout from '@/views/layout/index.vue'
import Login from '@/views/login/index.vue'
import PayBack from '@/views/pay/PayBack.vue'
import Pay from '@/views/pay/index.vue'
import SubCategory from '@/views/subCategory/index.vue'
import UserInfo from '@/views/user/components/UserInfo.vue'
import UserOrder from '@/views/user/components/UserOrder.vue'
import User from '@/views/user/index.vue'
import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/', component: Layout,
      children: [
        { path: '', component: Home },
        { path: '/category/:id', component: Category },
        { path: '/category/sub/:id', component: SubCategory },
        { path: '/detail/:id', component: Detail },
        { path: '/cartlist', component: CartList },
        { path: '/checkout', component: CheckOut },
        { path: '/pay', component: Pay },
        { path: '/payback', component: PayBack },
        {
          path: '/user', component: User,
          children: [
            {
              path: '',
              component: UserInfo
            },
            {
              path: 'order',
              component: UserOrder
            }
          ]
        }
      ]
    },
    {
      path: '/login', component: Login
    }
  ],
  //定义路由行为：切换分类时返回最顶部
  scrollBehavior () {
    return {
      top: 0
    }
  }
})


export default router
